<template>
  <el-dialog
    :model-value="show"
    title="FB广告账户编辑"
    width="800px"
    append-to-body
    :before-close="handleClose"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    class="form-label-120"
    destroy-on-close
  >
    <DynamicsForm
      ref="DynamicsFormRef"
      :api="companyResourceFbAdvActDetail"
      :params="formParams"
    />
    <template #footer>
      <el-button
        type="primary"
        :loading="submitLoading"
        :disabled="!show"
        @click="submitApply"
      >
        提交
      </el-button>
      <el-button type="info" @click="handleClose">取消</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import {
  companyResourceFbAdvActUpdate,
  companyResourceFbAdvActDetail
} from '@/api/resources';
import DynamicsForm from '@/components/DynamicsForm';
const props = defineProps({
  show: {
    type: Boolean,
    default: false
  },
  activeRow: {
    type: Array,
    default: () => {}
  }
});
const emit = defineEmits();

const formParams = computed(() => {
  return { id: props.activeRow.id, view_type: 2 };
});

// 关闭
function handleClose() {
  emit('update:show', false);
}

// 提交
const DynamicsFormRef = ref();
const submitLoading = ref(false);
async function submitApply() {
  try {
    submitLoading.value = true;
    const values = await DynamicsFormRef.value.returnData();
    companyResourceFbAdvActUpdate({ values })
      .then(() => {
        $msg.success('编辑站点资源信息成功');
        emit('success');
        handleClose();
      })
      .finally(() => {
        submitLoading.value = false;
      });
  } catch {
    submitLoading.value = false;
  }
}

// 初始化表单
watch(
  () => props.show,
  async val => {
    if (!val) return;
    await nextTick();
    DynamicsFormRef.value?.initFormList();
  }
);
</script>

<style lang="scss" scoped>
// :deep(.form-title) {
//   font-weight: 800;
//   font-size: 15px;
//   width: 100%;
//   margin-bottom: 20px;
//   color: var(--el-color-primary-light-1);
//   padding-left: 0;
//   &::before {
//     display: none;
//   }
// }
</style>
